package com.atguigu.gmall.product.controller;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.model.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 品牌表 前端控制器
 *
 * @author atguigu
 * @since 2023-04-18
 */
@Api(tags = "品牌表控制器")
@RestController
@RequestMapping("/admin/product") //TODO 填写基础映射URL
public class BaseTrademarkController {

    @Autowired
    private BaseTrademarkService baseTrademarkService;
    
    /**
     * 分页查询品牌表
     * @param page
     * @param limit
     * @return
     */
    @GetMapping("/baseTrademark/{page}/{limit}")
    public Result baseTrademark(@PathVariable Long page, @PathVariable Long limit) {
        IPage<BaseTrademark> iPage = new Page<>(page,limit);
        iPage = baseTrademarkService.baseTrademark(iPage);
        return Result.ok(iPage);
    }
    
    /**
     * 添加品牌表
     * @param b
     * @return
     */
    
    @PostMapping("/baseTrademark/save")
    public Result baseTrademark(@RequestBody BaseTrademark b) {
        baseTrademarkService.save(b);
        return Result.ok();
    }
    
    /**
     * 根据id查询品牌对象
     * @param id
     * @return
     */
    
    @GetMapping("/baseTrademark/get/{id}")
    public Result baseTrademark(@PathVariable Long id) {
        BaseTrademark byId = baseTrademarkService.getById(id);
        return Result.ok(byId);
    }
    
    /**
     * 更新品牌
     * @return
     */
    @PutMapping("/baseTrademark/update")
    public Result baseTrademark2(@RequestBody BaseTrademark baseTrademark) {
        baseTrademarkService.updateById(baseTrademark);
        return Result.ok();
    }
    
    /**
     * 根据id删除品牌
     * @param id
     * @return
     */
    
    @DeleteMapping("/baseTrademark/remove/{id}")
    public Result baseTrademark2(@PathVariable Long id) {
        baseTrademarkService.removeById(id);
        return Result.ok();
    }
    
   
}
